import apiClient from '@/api/axios.js';

export class AdminManagementApi {
    // 按月获取交易量（订单数和金额）
    static async getMonthlyTransactionTotal() {
        try {
            const response = await apiClient.get('/admin-management/total/monthly');
            return response.data; // 返回按月交易数据
        } catch (error) {
            throw new Error(error.message || '获取按月交易量失败');
        }
    }

    // 获取交易总量（订单数和金额）
    static async getTotalTransaction() {
        try {
            const response = await apiClient.get('/admin-management/total');
            return response.data; // 返回总交易数据
        } catch (error) {
            throw new Error(error.message || '获取交易总量失败');
        }
    }

    // 按月获取文章总量
    static async getMonthlyArticleCount() {
        try {
            const response = await apiClient.get('/admin-management/count/monthly');
            return response.data; // 返回按月文章数据
        } catch (error) {
            throw new Error(error.message || '获取按月文章总量失败');
        }
    }

    // 获取文章总量
    static async getTotalArticleCount() {
        try {
            const response = await apiClient.get('/admin-management/count');
            return response.data; // 返回文章总量数据
        } catch (error) {
            throw new Error(error.message || '获取文章总量失败');
        }
    }

    // 处理举报
    static async handleReport(reportId, handlingResult) {
        try {
            const response = await apiClient.put('/admin-management/handle', {}, {
                params: { reportId, handlingResult },
            });
            return response.data; // 返回处理结果
        } catch (error) {
            throw new Error(error.message || '处理举报失败');
        }
    }

    // 获取所有未处理的举报
    static async getPendingReports() {
        try {
            const response = await apiClient.get('/admin-management/report');
            return response.data; // 返回未处理举报列表
        } catch (error) {
            throw new Error(error.message || '获取未处理举报失败');
        }
    }

    // 将文章打回草稿状态
    static async draftArticle(articleId) {
        try {
            const response = await apiClient.put('/admin-management/draft', {}, {
                params: { articleID: articleId },
            });
            return response.data; // 返回操作结果
        } catch (error) {
            throw new Error(error.message || '将文章打回草稿状态失败');
        }
    }

    // 更改文章为发布状态
    static async publishArticle(articleId) {
        try {
            const response = await apiClient.put('/admin-management/publish', {}, {
                params: { articleId },
            });
            return response.data; // 返回操作结果
        } catch (error) {
            throw new Error(error.message || '更改文章为发布状态失败');
        }
    }

    // 获取未审核的文章
    static async getPendingArticles() {
        try {
            const response = await apiClient.get('/admin-management/pending');
            return response.data; // 返回未审核文章列表
        } catch (error) {
            throw new Error(error.message || '获取未审核文章失败');
        }
    }
}